import java.util.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.Point;

public class Monkey
{
	private int range;
	private int speed;
	private int damage;
	private int x;
	private int y;
	private Place myLocation = new Place(x, y);
	private ArrayList<Bloon> bloonsToShoot;
	
	
	public Monkey(int xCoord, int yCoord, int rang, int sped, int dam)
	{
		x = xCoord;
		y = yCoord;
		range = rang;
		speed = sped;
		damage = dam;
	}
	public Bloon bloonsInRange()
	{
		int max = 0;
		bloonsToShoot = BloonCreator.BloonsOnMap();
		for(int i = 0; i <= bloonsToShoot.size(); i++)
		{
			if(bloonsToShoot.get(i).getLocation().distance(myLocation) <= range)
			{
				
				for(int j = 0; j < bloonsToShoot.size(); j++)
				{
					if (bloonsToShoot.get(i).pos() > max)
						max = i;
				}
			}
			
		}
		return bloonsToShoot.get(max);
	}
	public void popBloon()
	{
		if(bloonsInRange() != null)
		{
			for(int i = 0; i < damage; i++)
			{
				bloonsInRange().pop();		
			}
		}
	}
	public void speed()
	{
		popBloon();
		wait(speed);
	}
	public static void wait (int n)
	  {
	        
	        long t0, t1;

	        t0 =  System.currentTimeMillis();

	        do{
	            t1 = System.currentTimeMillis();
	        }
	        while (t1 - t0 < n);
	    }
	public void setDirectionOfMonkey()
	{
		double xc, yc;
		double tempAngle;
		if (bloonsInRange() != null)
		{
			Point target = bloonsInRange().getLocation();
			xc = target.getX();
			yc = target.getY();
			tempAngle = Math.atan(Math.abs((y-yc)/(x-xc)));
			
		}
	}
	
	public int getX()
	{
		return x;
	}
	
	public int getY()
	{
		return y;
	}
	
	public int getRadius()
	{
		return range;
	}
}
